package com.xy;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/6/18 20:36
 * @description
 */
public class Caretaker {
    private List<Memento> mementos = new ArrayList<>();

    /**
     * 添加状态
     */
    public void addState(Memento memento) {
        System.out.println("添加存档:" + memento.getState());
        mementos.add(memento);
    }

    /**
     * 获取状态
     */
    public Memento getState(int index) {
        Memento memento = mementos.get(index);
        System.out.println("恢复存档:" + memento.getState());
        return memento;
    }
}
